load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target")
load("@fbcode_macros//build_defs:cpp_benchmark.bzl", "cpp_benchmark")
load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest")
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE", "CXX", "FBCODE", "WINDOWS")
load("@fbsource//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library")
load("@fbsource//tools/build_defs:glob_defs.bzl", "subdir_glob")
load("@fbsource//xplat/folly:defs.bzl", "DEFAULT_APPLE_SDKS")

oncall("fbcode_entropy_wardens_folly")

non_fbcode_target(
    _kind = fb_xplat_cxx_library,
    name = "test-headers",
    header_namespace = "",
    exported_headers = subdir_glob(
        [
            ("", "**/*.h"),
        ],
        prefix = "folly/concurrency/test",
    ),
    apple_sdks = DEFAULT_APPLE_SDKS,
    force_static = True,
    platforms = (ANDROID, APPLE, CXX, FBCODE, WINDOWS),
    visibility = ["PUBLIC"],
)

# !!!! fbcode/folly/concurrency/test/TARGETS was merged into this file, see https://fburl.com/workplace/xl8l9yuo for more info !!!!

fbcode_target(
    _kind = cpp_binary,
    name = "cache_locality_benchmark",
    srcs = ["CacheLocalityBenchmark.cpp"],
    headers = [],
    deps = [
        "//folly:benchmark",
        "//folly/concurrency:cache_locality",
        "//folly/lang:keep",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "cache_locality_test",
    srcs = ["CacheLocalityTest.cpp"],
    headers = [],
    deps = [
        "fbsource//third-party/fmt:fmt",
        "//folly/concurrency:cache_locality",
        "//folly/portability:gtest",
        "//folly/portability:sys_resource",
        "//folly/portability:unistd",
        "//folly/test:test_utils",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "atomic_shared_ptr_test",
    srcs = ["AtomicSharedPtrTest.cpp"],
    headers = ["AtomicSharedPtrCounted.h"],
    labels = ["case-isolation-failure"],
    deps = [
        "//folly:portability",
        "//folly/concurrency:atomic_shared_ptr",
        "//folly/portability:config",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/test:deterministic_schedule",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_binary,
    name = "atomic_shared_ptr_performance",
    srcs = ["AtomicSharedPtrPerformance.cpp"],
    deps = [
        "//folly/concurrency:atomic_shared_ptr",
        "//folly/portability:config",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "core_cached_shared_ptr_test",
    srcs = ["CoreCachedSharedPtrTest.cpp"],
    headers = [],
    deps = [
        "//folly:benchmark",
        "//folly:portability",
        "//folly/concurrency:atomic_shared_ptr",
        "//folly/concurrency:core_cached_shared_ptr",
        "//folly/concurrency:thread_cached_synchronized",
        "//folly/concurrency/memory:read_mostly_shared_ptr",
        "//folly/portability:config",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "concurrent_hash_map_bench",
    srcs = ["ConcurrentHashMapBench.cpp"],
    headers = [],
    deps = [
        "//folly:benchmark_util",
        "//folly/concurrency:concurrent_hash_map",
        "//folly/portability:gflags",
        "//folly/synchronization/test:barrier",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "concurrent_hash_map_stress_test",
    srcs = ["ConcurrentHashMapStressTest.cpp"],
    labels = [
        "heavyweight",
        "slow",
    ],
    supports_static_listing = False,
    deps = [
        "//folly:traits",
        "//folly/concurrency:concurrent_hash_map",
        "//folly/portability:gtest",
        "//folly/synchronization:latch",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "concurrent_hash_map_test",
    srcs = ["ConcurrentHashMapTest.cpp"],
    supports_static_listing = False,
    deps = [
        "//folly:traits",
        "//folly/concurrency:concurrent_hash_map",
        "//folly/container/test:tracking_types",
        "//folly/hash:hash",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/synchronization:latch",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "concurrent_hash_map_stress_test_no_simd",
    srcs = ["ConcurrentHashMapStressTest.cpp"],
    labels = [
        "heavyweight",
        "slow",
    ],
    preprocessor_flags = ["-DFOLLY_F14_FORCE_FALLBACK=1"],
    supports_static_listing = False,
    deps = [
        "//folly:traits",
        "//folly/concurrency:concurrent_hash_map",
        "//folly/portability:gtest",
        "//folly/synchronization:latch",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "concurrent_hash_map_test_no_simd",
    srcs = ["ConcurrentHashMapTest.cpp"],
    preprocessor_flags = ["-DFOLLY_F14_FORCE_FALLBACK=1"],
    supports_static_listing = False,
    deps = [
        "//folly:traits",
        "//folly/concurrency:concurrent_hash_map",
        "//folly/container/test:tracking_types",
        "//folly/hash:hash",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/synchronization:latch",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "dynamic_bounded_queue_test",
    srcs = ["DynamicBoundedQueueTest.cpp"],
    headers = [],
    deps = [
        "//folly:mpmc_queue",
        "//folly:producer_consumer_queue",
        "//folly/concurrency:dynamic_bounded_queue",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "priority_unbounded_queue_set_test",
    srcs = ["PriorityUnboundedQueueSetTest.cpp"],
    deps = [
        "//folly/concurrency:priority_unbounded_queue_set",
        "//folly/container:enumerate",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "unbounded_queue_test",
    srcs = ["UnboundedQueueTest.cpp"],
    headers = [],
    deps = [
        "//folly:mpmc_queue",
        "//folly:producer_consumer_queue",
        "//folly/concurrency:unbounded_queue",
        "//folly/lang:keep",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
    ],
    external_deps = [
        ("boost", None, "boost_thread"),
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "thread_cached_synchronized_bench",
    srcs = ["ThreadCachedSynchronizedBench.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:synchronized",
        "//folly/concurrency:thread_cached_synchronized",
        "//folly/lang:keep",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "thread_cached_synchronized_test",
    srcs = ["ThreadCachedSynchronizedTest.cpp"],
    deps = [
        "//folly/concurrency:thread_cached_synchronized",
        "//folly/lang:keep",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "process_local_unique_id_test",
    srcs = ["ProcessLocalUniqueIdTest.cpp"],
    deps = [
        "//folly:synchronized",
        "//folly/concurrency:process_local_unique_id",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_binary,
    name = "singleton_relaxed_counter_bench",
    srcs = [
        "SingletonRelaxedCounterBench.cpp",
    ],
    deps = [
        "//folly:benchmark",
        "//folly/concurrency:singleton_relaxed_counter",
        "//folly/init:init",
        "//folly/lang:keep",
        "//folly/portability:gflags",
    ],
    external_deps = [
        ("boost", None, "boost_thread"),
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "singleton_relaxed_counter_test",
    srcs = [
        "SingletonRelaxedCounterTest.cpp",
    ],
    deps = [
        "//folly:thread_local",
        "//folly/concurrency:singleton_relaxed_counter",
        "//folly/portability:gtest",
    ],
    external_deps = [
        ("boost", None, "boost_thread"),
    ],
)
